# -*- python -*-
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Import('env')


srpc_test_objs = env.ComponentObject('srpc_test', 'srpc_test.c')
srpc_test_libs = ['srpc', 'imc_syscalls', 'platform', 'gio', 'm']

srpc_test_nonbrowser = env.ComponentProgram(
    'srpc_test_nonbrowser', srpc_test_objs,
    EXTRA_LIBS=srpc_test_libs + ['${PTHREAD_LIBS}', '${NONIRT_LIBS}'])


# NOTE: at least for ARM the EXTRA_LIBS list should include 'srpc'
#       but this somehow make the x86 version fragile
srpc_bad_service_nexe_name = env.ProgramNameForNmf('srpc_bad_service')
srpc_bad_service_nexe = env.ComponentProgram(
    srpc_bad_service_nexe_name, 'srpc_bad_service.c',
    EXTRA_LIBS=['imc_syscalls', 'm', '${PTHREAD_LIBS}', '${NONIRT_LIBS}'])
env.Publish(srpc_bad_service_nexe_name, 'run', [])

######################################################################
## Automated testing using sel_universal
######################################################################

node = env.SelUniversalTest(
    'srpc_basic_test.out',
    srpc_test_nonbrowser,
    sel_universal_flags=['--command_file', env.File('srpc_basic_test.stdin')],
    stdout_golden=env.File('srpc_basic_test.stdout'),
    )
env.AddNodeToTestSuite(node,
                       ['sel_ldr_tests', 'small_tests'],
                       'run_srpc_basic_test')

node = env.SelUniversalTest(
    'srpc_bad_service.out',
    srpc_bad_service_nexe,
    exit_status='1'
    )
env.AddNodeToTestSuite(node,
                       ['sel_ldr_tests', 'small_tests'],
                       'run_srpc_bad_service_test')
